﻿Imports System.Data
Imports System.Data.Odbc
Imports WSEntidades
Imports Utilerias
Imports Npgsql
Imports MySql.Data.MySqlClient

Public Class CatServidoresFact
    Public Shared Function Build(ByVal dr As MySqlDataReader) As CatServidoresBE
        Dim tmpCatServidores As CatServidoresBE = New CatServidoresBE()
        Try
            With tmpCatServidores
                .Id = convertDTFromDb.convertInt32(dr.Item("IdServidor"))
                .Descripcion = convertDTFromDb.ConvertString(dr.Item("Descripcion"))
                .Host = convertDTFromDb.ConvertString(dr.Item("Host"))
                .Puerto = convertDTFromDb.ConvertString(dr.Item("Port"))
                .Usuario = convertDTFromDb.ConvertString(dr.Item("Username"))
                .Pass = RijndaelSimple.desencriptaDefault(dr.Item("Password"))
                Select Case convertDTFromDb.ConvertString(dr.Item("Estatus"))
                    Case "A"
                        .Status = CatServidoresBE.EstatusServidor.Activo
                    Case "I"
                        .Status = CatServidoresBE.EstatusServidor.Inactivo
                    Case Else
                        .Status = CatServidoresBE.EstatusServidor.Inactivo
                End Select
                .CantidadBD = convertDTFromDb.convertInt32(dr.Item("CapacidadBD"))
                .CantDisponiblesBD = convertDTFromDb.convertInt32(dr.Item("DisponiblesBD"))
            End With
            Return tmpCatServidores
        Catch ex As Exception
            Throw
        Finally
            tmpCatServidores = Nothing
        End Try
    End Function

    Public Shared Function BuildForConnString(ByVal dr As MySqlDataReader) As CatServidoresBE
        Dim tmpCatServidores As CatServidoresBE = New CatServidoresBE()
        Try
            With tmpCatServidores
                .Id = 0
                .Descripcion = """"
                .Host = convertDTFromDb.ConvertString(dr.Item("Host"))
                .Puerto = convertDTFromDb.ConvertString(dr.Item("Port"))
                .Usuario = convertDTFromDb.ConvertString(dr.Item("Username"))
                .Pass = RijndaelSimple.desencriptaDefault(dr.Item("Password"))
                .Status = CatServidoresBE.EstatusServidor.Activo
                .CantidadBD = 0
                .CantDisponiblesBD = 0
            End With
            Return tmpCatServidores
        Catch ex As Exception
            Throw
        Finally
            tmpCatServidores = Nothing
        End Try
    End Function

End Class
